<template>
    <div class="section">
        <div v-for="item in photoinfo" :key="item.id">
            <h3>{{item.title}}</h3>
            <p class="info-mess">
                <span>编辑时间：{{item.add_time | datemsg}}</span>
                <span>点击次数：{{item.click}}</span>
            </p>
            <p v-html="item.content" class="info-body"></p>
        </div>
        <!--  -->
        <vue-preview :slides="this.photothum" class="photothum"></vue-preview>
        <div class="clear"></div>
        <comment :sonmsg="id"></comment>
    </div>
</template>

<script>

import { Toast } from 'mint-ui';
import comment from '../subcomponents/comment.vue';

export default {
    data() {
        return {
            id: this.$route.params.id,
            photoinfo: [],
            photothum: []
        }
    },
    methods: {
        // 图片详情
        getphotoinfo(id){
            this.$http.get('api/getimageInfo/' + id).then(res => {
                if(res.body.status == 0){
                    this.photoinfo = res.body.message;
                }else{
                    Toast('获取图片详情失败')
                }
            })
        },
        // 缩略图
        getphotothum(id){
            this.$http.get('api/getthumimages/' + id).then(res => {
                if(res.body.status == 0){
                    // forEach手动向数组里添加宽高
                    res.body.message.forEach(e => {
                        e.msrc = e.src;
                        e.w = 600;
                        e.h = 600;
                    });
                    this.photothum = res.body.message;
                    // console.log(this.photothum);
                }else{
                    Toast('获取缩略图失败')
                }
            })
        }
    },
    created() {
        // console.log(this.id);
        this.getphotoinfo(this.id);
        this.getphotothum(this.id);
    },
    components: {
        'comment': comment
    }
}
</script>

<style lang="less" scoped>
    .section{
        padding: 10px;
        h3{
            font-size: 16px;
            text-align: center;
            line-height: 25px;
            margin: 5px 0;
        }
        .info-mess{
            display: flex;
            justify-content: space-around;
            margin-bottom: 5px;
            color: #666;
        }
        .info-body{
            margin-bottom: 5px;
            color: #333;
        }
    }
</style>